StarterGui:SetCore必须从本地脚本中调用。

huangapple go评论57阅读模式
英文:

StarterGui:SetCore must be called from a local script

问题

以下是您要的中文翻译:

服务器端:

local gui = game:GetService("StarterGui")
local Players = game:GetService("Players")
local pp = game:GetService("ProximityPromptService")
local phone = game:GetService("ReplicatedStorage")
local world = game.Workspace

local function pptrig(obj, ply)
    for i, v in pairs(game.Players:GetChildren()) do
        local player = world:FindFirstChild(v.Name)
        local nuke = Instance.new("Explosion", world)
        nuke.BlastRadius = 0.9
        nuke.BlastPressure = 1000000
        nuke.Position = player.HumanoidRootPart.Position
        print("run")
        phone.Exploded:FireClient(v, v.Name, ply.Name)
    end
end

pp.PromptTriggered:Connect(pptrig)

客户端:

local phone = game:GetService("ReplicatedStorage")
local gui = game:GetService("StarterGui")

gui:SetCore("test", {Text = "Ran"})

local function humiliation(me, ply)
    gui:SetCore("test", {Text = "Ran"})
    if ply ~= me then
        gui:SetCore("Humiliation", {
            Title = "Exploded!",
            Text = "You have been exploded by " .. ply .. ".",
            Duration = 10,
        })
    elseif ply == me then
        gui:SetCore("Humiliation", {
            Title = "Exploded!",
            Text = "You, " .. me .. ", exploded yourself."
        })
    end
end

phone.Exploded.OnClientEvent:Connect(humiliation())

当我尝试运行它时,它给我这个错误信息:

必须从本地脚本中调用StarterGui:SetCore。 (x2)  -  Studio
Players.GoldenRStar.PlayerGui.Script:19: 尝试将nil与字符串连接  -  服务器端 - 脚本:19

"Exploded" 是一个远程事件,我想要爆炸每个人并发送他们一条消息:"You have been exploded by GuyThatPressesButtons." 和 "You, GuyThatPressesButtons, exploded yourself." 这个程序尝试循环遍历每个玩家,爆炸他们并发送远程事件 "Exploded",然后客户端脚本捕捉并相应处理它。在触发事件时,发送了玩家的名称:v.Name 和按下按钮的玩家名称,但在客户端脚本中两个值都是nil。

英文:

So... I am trying to explode everyone and send them a message but it is not working. Here is the code.

Serverside:

local gui = game:GetService("StarterGui")

local Players = game:GetService("Players")

local pp = game:GetService("ProximityPromptService")

local phone = game:GetService("ReplicatedStorage")

local world = game.Workspace

local function pptrig (obj, ply)
	for i,v in pairs(game.Players:GetChildren()) do
		local player = world:FindFirstChild(v.Name)
		local nuke = Instance.new("Explosion", world)
		nuke.BlastRadius = 0.9
		nuke.BlastPressure = 1000000
		nuke.Position = player.HumanoidRootPart.Position
		print("run")
		phone.Exploded:FireClient(v, v.Name, ply.Name)
	end	
end

pp.PromptTriggered:Connect(pptrig)

Clientside:

local phone = game:GetService("ReplicatedStorage")

local gui = game:GetService("StarterGui")

gui:SetCore("test", {Text = "Ran"})

local function humiliation(me, ply)
	
	gui:SetCore("test", {Text = "Ran"})
	if ply ~= me then
		gui:SetCore("Humiliation", {
			Title = "Exploded!",
			Text = "You have been exploded by "..ply..".",
			Duration = 10,
		})
	elseif ply == me then
		gui:SetCore("Humiliation", {
			Title = "Exploded!",
			Text = "You, "..me..", exploded yourself."
		})
	end
end

phone.Exploded.OnClientEvent:Connect(humiliation())

When I try to run it it gives me this:

StarterGui:SetCore must be called from a local script. (x2)  -  Studio
Players.GoldenRStar.PlayerGui.Script:19: attempt to concatenate nil with string  -  Server - Script:19

Exploded is a remote event and I wanted to Explode everyone and send them a message:
"You have been exploded by GuyThatPressesButtons." and
"You, GuyThatPressesButtons, exploded yourself."

this program tries to loop though every player, explodes them and sends them a fire from the remote event Exploded, then a client script catches it and processes it acordingly.
on the fire, it is sent the players name: v.Name and the player that pressed the button, on the client script both values are nil.

答案1

得分: 0

我实际上在使用一个服务器脚本。
我需要在客户端运行这个脚本。
Roblox有3种类型的脚本,服务器脚本、本地脚本和模块脚本,由于服务器脚本只是命名为脚本,我以为Roblox会自动区分服务器和客户端脚本。

英文:

I was actually using a server script.
I needed to run this script in the client side.
Roblox has 3 types of scripts, server scripts, local scripts and module scripts, since the server scripts are just named scripts, i thought that roblox automatically distinguished between server and client scripts.

huangapple
  • 本文由 发表于 2023年2月20日 00:37:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/75501684.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定