We aren't limited to using a remoteevent for this since the server can see inside a player's playergui.
The reason your script won't work is because you are attempting to use localplayer which can only be used on a localscript.
To fix this we need to get the character's player instance and use that for finding the playergui. We can use the GetPlayerFromCharacter() function of player
so
local part = game.workspace.BattleSigil1.PartSigil1friendly
local part1 = game.workspace.BattleSigil1.PartSigil1enemy
function onTouched(hit)
print("hit")
local character = hit.Parent
if character and character:findFirstChild("Humanoid") then
local b = Instance.new("BodyPosition")
b.position = Vector3.new(part.Position.X,part.Position.Y +0.5,part.Position.Z)
b.maxForce = Vector3.new(50000, 50000, 50000)
b.Parent = character.UpperTorso
local character1 = script.Parent
local b1 = Instance.new("BodyPosition")
b1.position = Vector3.new(part1.Position.X,part1.Position.Y +0.5,part1.Position.Z)
b1.maxForce = Vector3.new(50000, 50000, 50000)
b1.Parent = character1
print("init battle")
local plr=game.Players:GetPlayerFromCharacter(character)
local Playergui = plr:WaitForChild("PlayerGui")
local Spells = Playergui.BattleSigilSpells.Frame
end
end
script.Parent.Touched:connect(onTouched)
SECOND WAY
yes you could use a remoteevent, but how?
First things first, in your server script we need to set the remoteevent variable, specifically at the begginging of the script, then when the part is touched, we fire to the client of the player who touched it.
So after a character touches the part, we need to get its player instance and send that through the remoteevent. We can use the GetPlayerFromCharacter() function of player
ServerScript
local rem = game.ReplicatedStorage.RemoteEvent
local part = game.workspace.BattleSigil1.PartSigil1friendly
local part1 = game.workspace.BattleSigil1.PartSigil1enemy
function onTouched(hit)
print("hit")
local character = hit.Parent
if character and character:findFirstChild("Humanoid") then
local b = Instance.new("BodyPosition")
b.position = Vector3.new(part.Position.X,part.Position.Y +0.5,part.Position.Z)
b.maxForce = Vector3.new(50000, 50000, 50000)
b.Parent = character.UpperTorso
local character1 = script.Parent
local b1 = Instance.new("BodyPosition")
b1.position = Vector3.new(part1.Position.X,part1.Position.Y +0.5,part1.Position.Z)
b1.maxForce = Vector3.new(50000, 50000, 50000)
b1.Parent = character1
print("init battle")
local plr=game.Players:GetPlayerFromCharacter(character)
rem:FireClient(plr)
end
end
script.Parent.Touched:connect(onTouched)
Now on the client we need to set a event function for when that remoteevent is triggered. When there is an event we will run the code needed
Make sure it is a localscript located somewhere like starterGui.
LocalScript
local rem = game.ReplicatedStorage.RemoteEvent
rem.OnClientEvent:Connect(function()
local Playergui = script.Parent
local Spells = Playergui.BattleSigilSpells.Frame
local rem = game.ReplicatedStorage.RemoteEvent
end)
And tada! Let me know if you have questions.